#include "widget.h"
#include "ui_widget.h"

#include <string>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // 启动一个定时器, 并返回定时器的 id1
    this->timer_id_1 =  startTimer(500); // 参数毫秒
    // 启动一个定时器, 并返回定时器的 id2
    this->timer_id_2 =  startTimer(1000); // 参数毫秒
}

Widget::~Widget()
{
    delete ui;
}

// timerEvent 函数将处理全部的 startTimer 启动的定时器
void Widget::timerEvent(QTimerEvent *event)
{
    if (event->timerId() == this->timer_id_1) {
        static int count1 = 0;
        this->ui->label_1->setText(QString::number(count1++));
    }

    if (event->timerId() == this->timer_id_2) {
        static int count2 = 0;
        this->ui->label_2->setText(QString::number(count2++));
    }
}
